# Maintainer: Morten Linderud <foxboron@archlinux.org>
# Maintainer: Frederik Schwan <freswa at archlinux dot org>
# Contributor: Sébastien "Seblu" Luttringer

pkgname=runc
pkgver=1.1.10
pkgrel=1
pkgdesc='CLI tool for managing OCI compliant containers'
arch=(loong64 x86_64)
url='https://runc.io/'
license=(Apache)
provides=('oci-runtime')
depends=(libseccomp)
makedepends=(git go go-md2man)
optdepends=(
  'criu: checkpoint support'
)
source=("${pkgname}-${pkgver}.tar.xz::https://github.com/opencontainers/runc/releases/download/v${pkgver}/runc.tar.xz"
        "${pkgname}-${pkgver}.tar.xz.sig::https://github.com/opencontainers/runc/releases/download/v${pkgver}/runc.tar.xz.asc"
        runc-la64.patch)
validpgpkeys=("5F36C6C61B5460124A75F5A69E18AA267DDB8DB4"
			  "C9C370B246B09F6DBCFC744C34401015D1D2D386")
sha256sums=('bd3e89ae89319ef344e7e26f392b40e344bcd5bbdea84ca459a43189451615bf'
            'SKIP'
            '6027791a177bbc22751eecd0bca41ffc4287fbdbdd757c27dab6cd29e0d425f4')

prepare() {
  mkdir -p src/github.com/opencontainers
  cp -r runc-${pkgver} src/github.com/opencontainers/runc
  patch -d ${pkgname}-${pkgver} -p1 -i $srcdir/runc-la64.patch
}

build() {
  cd src/github.com/opencontainers/runc
  export GOPATH="$srcdir"
  export BUILDTAGS='seccomp apparmor'
  export CGO_CPPFLAGS="${CPPFLAGS}"
  export CGO_CFLAGS="${CFLAGS}"
  export CGO_CXXFLAGS="${CXXFLAGS}"
  export CGO_LDFLAGS="${LDFLAGS}"
  export GOFLAGS="-trimpath -mod=readonly -modcacherw"
  export GOPROXY=https://goproxy.cn
  go mod edit -replace=golang.org/x/sys=github.com/golang/sys@v0.0.0-20220622161953-175b2fd9d664
  go mod edit -replace=golang.org/x/net=github.com/golang/net@v0.0.0-20220622184535-263ec571b305
  go mod tidy
  make GO_BUILDMODE="" runc man || true
# patch the depends code
  cd $srcdir && patch -d src/github.com/opencontainers/runc/ -p1 -i $srcdir/runc-la64.patch
  cd src/github.com/opencontainers/runc
  make GO_BUILDMODE="" runc man
}

package() {
  cd src/github.com/opencontainers/runc

  install -Dm755 runc "$pkgdir/usr/bin/runc"
  install -Dm644 contrib/completions/bash/runc \
    "$pkgdir/usr/share/bash-completion/completions/runc"

  install -d "$pkgdir/usr/share/man/man8"
  install -m644 man/man8/*.8 "$pkgdir/usr/share/man/man8"
}
